#!/usr/bin/env python

import nxt.locator
import nxt.brick

def query_brick_info(b):
	prot_version, fw_version = b.get_firmware_version()
	print 'Protocol version %s.%s' % prot_version
	print 'Firmware version %s.%s' % fw_version
	name, host, signal_strength, user_flash = b.get_device_info()
	print 'NXT brick name: %s' % name
	print 'Host address: %s' % host
	print 'Bluetooth signal strength: %s' % signal_strength
	print 'Free user flash: %s' % user_flash
	millivolts = b.get_battery_level()
	print 'Battery level %s mV' % millivolts
	print '\nModules:'
	# FIXME: change to "with" syntax for python 2.5
	# with nxt.brick.ModuleFinder(b, '*.*') as m:
	#	for values in m:
	#		print '\t'.join('%s' % v for v in values)
	m = nxt.brick.ModuleFinder(b, '*.*')
	try:
		for values in m:
			print '\t'.join('%s' % v for v in values)
	finally:
		m.__exit__(None, None, None)

socks = nxt.locator.find_bricks()
for sock in socks:
	query_brick_info(sock.connect())
	sock.close()
